#ifndef mW_interface_include
#define mW_interface_include



#include <allegro.h>
#include <string.h>
#include "list.h"
#include "mouse.h"
#include "error.h"



/*
 * type
 * 0000 0 = regular textbox
 * 0000 1 = select input textbox
 * 000X   = this textbox can be dismissed by the user by clicking on it
 */
typedef struct _mW_interface_textbox
{
	unsigned char type;
	int left;
	int top;
	int width;
	int height;
	char * text;
} mW_interface_textbox;

/*
 * options is a list containing the strings of the questions
 * textboxes for the selectbox are made dynamically
 */
typedef struct 
{
	mW_list * options;
	int left;
	int top;
	int width;
	int height;
} mW_interface_selectbox;

/*
 * This is the struct which is returned from mW_interface_selectbox_event()
 * Contains information about a selectbox which was clicked
 */
typedef struct
{
	unsigned int selectbox_id;
	unsigned int option_id;
} mW_interface_selectbox_event;


mW_list * mW_interface_textboxes;
mW_list * mW_interface_selectboxes;
mW_list * mW_interface_selectbox_events;
	


/*
 * Draws all components of the interface to the passed surface
 * First draws all of the textboxes
 * Second draws all of the selectboxes
 * Returns 1 on success
 */
int mW_interface_draw (BITMAP * surface);

/*
 * Draws a passed textbox to the passed screen
 * Returns 1 on success
 */
int mW_interface_draw_textbox (BITMAP * surface, mW_interface_textbox * textbox);

/*
 * Initializes the interface
 * Creates a mW_list for mW_interface_textboxes
 * Creates a mW_list for mW_interface_selectboxes
 * Returns 1 on success
 * Returns 0 on failure
 */
int mW_interface_init ();

/*
 * Handles mouse input for the interface
 * Automatically removes user dismissed textboxes
 * Returns 0 if nothing happened
 * Returns 1 if a user dismissed textbox was dismissed
 * Returns 2 if a selectbox option was clicked and there is a selectbox_event
 *   waiting in mW_interface_selectbox_events 
 *   (developer should call mW_interface_selectbox_get_event())
 */
int mW_interface_input ();

/*
 * Adds an option with passed text to passed selectbox
 * Copies option_text into newly allocated memory
 * Returns the id of the option on success
 * Prints an error message if memory for option_text cannot be allocated,
 *   but the error is otherwise unhandled. Not ideal, most likely will
 *   lead to a crash
 */
int mW_interface_selectbox_add_option (int selectbox_id, char * option_text);

/*
 * Creates an empty selectbox at the passed coordinates
 * Returns an initialized mW_interface_selectbox * on success
 * Returns NULL On failure
 */
int mW_interface_selectbox_create (int left, int top);

/*
 * Destroys a selectbox, freeing all memory
 * Returns 1 on success
 * Return 0 on failure
 */
int mW_interface_selectbox_destroy (int selectbox_id);

/*
 * Returns mW_interface_selectbox_event * containing information about
 *   the last selectbox that was clicked, and then removes that selectbox
 *   from the list
 * Returns NULL if there are no selectbox events in the list
 * Selectbox events are added to the list in mW_interface_input()
 * Returned value should be freed when user is done with it
 */
mW_interface_selectbox_event * mW_interface_selectbox_get_event();

/*
 * Creates a textox with the passed text at the passed coordinates
 * Copies text into newly allocated memory
 * Returns the id of the textbox on success
 * Prints an error message if there is an error allocating memory, but
 *   the error is otherwise unhandled, most likely leading to a crash
 */
int mW_interface_textbox_create (char * text, int left, int top, unsigned char type);

/*
 * Destroys a textbox, freeing all memory
 * Returns 1 on success
 * Returns 0 on failure
 */
int mW_interface_textbox_destroy (int id);

#endif // mW_interface_include
